// $ANTLR 2.7.5 (20050128): "shoiq.g" -> "FormulaTreeParser.java"$

  package tr.edu.ege.kipler.parsing;
  import tr.edu.ege.kipler.*;
  import tr.edu.ege.kipler.satisfiability.*;
  import tr.edu.ege.kipler.satisfiability.container.*;
  import tr.edu.ege.kipler.syntax.*;
  import tr.edu.ege.kipler.syntax.atomicformula.*;
  import tr.edu.ege.kipler.syntax.concept.*;
  import var.syntax.*;
  import java.util.*;

import antlr.TreeParser;
import antlr.Token;
import antlr.collections.AST;
import antlr.RecognitionException;
import antlr.ANTLRException;
import antlr.NoViableAltException;
import antlr.MismatchedTokenException;
import antlr.SemanticException;
import antlr.collections.impl.BitSet;
import antlr.ASTPair;
import antlr.collections.impl.ASTArray;


public class FormulaTreeParser extends antlr.TreeParser       implements FormulaTreeParserTokenTypes
 {

   private Set<WorldElement> formulaSet = new LinkedHashSet<WorldElement>();
public FormulaTreeParser() {
	tokenNames = _tokenNames;
}

	public final Set<WorldElement>  world(AST _t) throws RecognitionException {
		Set<WorldElement> result = null;
		
		AST world_AST_in = (_t == ASTNULL) ? null : (AST)_t;
		
		try {      // for error handling
			boolean synPredMatched142 = false;
			if (((_t.getType()==WORLD))) {
				AST __t142 = _t;
				synPredMatched142 = true;
				inputState.guessing++;
				try {
					{
					AST __t141 = _t;
					AST tmp69_AST_in = (AST)_t;
					match(_t,WORLD);
					_t = _t.getFirstChild();
					namespaceArea(_t);
					_t = _retTree;
					_t = __t141;
					_t = _t.getNextSibling();
					}
				}
				catch (RecognitionException pe) {
					synPredMatched142 = false;
				}
				_t = __t142;
				inputState.guessing--;
			}
			if ( synPredMatched142 ) {
				AST __t143 = _t;
				AST tmp70_AST_in = (AST)_t;
				match(_t,WORLD);
				_t = _t.getFirstChild();
				namespaceArea(_t);
				_t = _retTree;
				semiColSeparatedFormula(_t);
				_t = _retTree;
				_t = __t143;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 result = formulaSet;
							
				}
			}
			else if ((_t.getType()==WORLD)) {
				AST __t144 = _t;
				AST tmp71_AST_in = (AST)_t;
				match(_t,WORLD);
				_t = _t.getFirstChild();
				semiColSeparatedFormula(_t);
				_t = _retTree;
				_t = __t144;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 result = formulaSet;
							
				}
			}
			else {
				throw new NoViableAltException(_t);
			}
			
		}
		catch (RecognitionException ex) {
			if (inputState.guessing==0) {
				reportError(ex);
				if (_t!=null) {_t = _t.getNextSibling();}
			} else {
			  throw ex;
			}
		}
		_retTree = _t;
		return result;
	}
	
	public final void namespaceArea(AST _t) throws RecognitionException {
		
		AST namespaceArea_AST_in = (_t == ASTNULL) ? null : (AST)_t;
		
		try {      // for error handling
			boolean synPredMatched155 = false;
			if (((_t.getType()==SEMICOLON))) {
				AST __t155 = _t;
				synPredMatched155 = true;
				inputState.guessing++;
				try {
					{
					AST __t154 = _t;
					AST tmp72_AST_in = (AST)_t;
					match(_t,SEMICOLON);
					_t = _t.getFirstChild();
					namespace(_t);
					_t = _retTree;
					namespace(_t);
					_t = _retTree;
					_t = __t154;
					_t = _t.getNextSibling();
					}
				}
				catch (RecognitionException pe) {
					synPredMatched155 = false;
				}
				_t = __t155;
				inputState.guessing--;
			}
			if ( synPredMatched155 ) {
				AST __t156 = _t;
				AST tmp73_AST_in = (AST)_t;
				match(_t,SEMICOLON);
				_t = _t.getFirstChild();
				namespace(_t);
				_t = _retTree;
				namespace(_t);
				_t = _retTree;
				_t = __t156;
				_t = _t.getNextSibling();
			}
			else if ((_t.getType()==SEMICOLON)) {
				AST __t157 = _t;
				AST tmp74_AST_in = (AST)_t;
				match(_t,SEMICOLON);
				_t = _t.getFirstChild();
				namespaceArea(_t);
				_t = _retTree;
				namespace(_t);
				_t = _retTree;
				_t = __t157;
				_t = _t.getNextSibling();
			}
			else if ((_t.getType()==NAMESPACE)) {
				namespace(_t);
				_t = _retTree;
			}
			else {
				throw new NoViableAltException(_t);
			}
			
		}
		catch (RecognitionException ex) {
			if (inputState.guessing==0) {
				reportError(ex);
				if (_t!=null) {_t = _t.getNextSibling();}
			} else {
			  throw ex;
			}
		}
		_retTree = _t;
	}
	
	public final void semiColSeparatedFormula(AST _t) throws RecognitionException {
		
		AST semiColSeparatedFormula_AST_in = (_t == ASTNULL) ? null : (AST)_t;
		WorldElement a, b;
		
		try {      // for error handling
			boolean synPredMatched148 = false;
			if (((_t.getType()==SEMICOLON))) {
				AST __t148 = _t;
				synPredMatched148 = true;
				inputState.guessing++;
				try {
					{
					AST __t147 = _t;
					AST tmp75_AST_in = (AST)_t;
					match(_t,SEMICOLON);
					_t = _t.getFirstChild();
					formula(_t);
					_t = _retTree;
					formula(_t);
					_t = _retTree;
					_t = __t147;
					_t = _t.getNextSibling();
					}
				}
				catch (RecognitionException pe) {
					synPredMatched148 = false;
				}
				_t = __t148;
				inputState.guessing--;
			}
			if ( synPredMatched148 ) {
				AST __t149 = _t;
				AST tmp76_AST_in = (AST)_t;
				match(_t,SEMICOLON);
				_t = _t.getFirstChild();
				a=formula(_t);
				_t = _retTree;
				b=formula(_t);
				_t = _retTree;
				_t = __t149;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 formulaSet.add(a);
							 formulaSet.add(b);
							
				}
			}
			else if ((_t.getType()==SEMICOLON)) {
				AST __t150 = _t;
				AST tmp77_AST_in = (AST)_t;
				match(_t,SEMICOLON);
				_t = _t.getFirstChild();
				semiColSeparatedFormula(_t);
				_t = _retTree;
				b=formula(_t);
				_t = _retTree;
				_t = __t150;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 formulaSet.add(b);
							
				}
			}
			else if ((_tokenSet_0.member(_t.getType()))) {
				{
				a=formula(_t);
				_t = _retTree;
				}
				if ( inputState.guessing==0 ) {
					
							 formulaSet.add(a);
							
				}
			}
			else {
				throw new NoViableAltException(_t);
			}
			
		}
		catch (RecognitionException ex) {
			if (inputState.guessing==0) {
				reportError(ex);
				if (_t!=null) {_t = _t.getNextSibling();}
			} else {
			  throw ex;
			}
		}
		_retTree = _t;
	}
	
	public final WorldElement  formula(AST _t) throws RecognitionException {
		WorldElement result = null;
		
		AST formula_AST_in = (_t == ASTNULL) ? null : (AST)_t;
		WorldElement a;
		
		try {      // for error handling
			if (_t==null) _t=ASTNULL;
			switch ( _t.getType()) {
			case BOX_BELIEF:
			case DIAMOND_BELIEF:
			{
				{
				result=modalFormula(_t);
				_t = _retTree;
				}
				break;
			}
			case COMMA:
			case AND:
			case OR:
			{
				{
				result=binaryBooleanFormula(_t);
				_t = _retTree;
				}
				break;
			}
			case IMPLIES_ROLE:
			case EQUALS:
			case IMPLIES:
			case TRANSITIVE:
			case DOUBLE_EQUAL:
			case CONCEPT_ASSERTION:
			case OBJECT_ROLE_ASSERTION:
			{
				{
				result=dlFormula(_t);
				_t = _retTree;
				}
				break;
			}
			case NOT:
			{
				AST __t166 = _t;
				AST tmp78_AST_in = (AST)_t;
				match(_t,NOT);
				_t = _t.getFirstChild();
				a=formula(_t);
				_t = _retTree;
				_t = __t166;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 result = a.toggleNegated();
							
				}
				break;
			}
			default:
			{
				throw new NoViableAltException(_t);
			}
			}
		}
		catch (RecognitionException ex) {
			if (inputState.guessing==0) {
				reportError(ex);
				if (_t!=null) {_t = _t.getNextSibling();}
			} else {
			  throw ex;
			}
		}
		_retTree = _t;
		return result;
	}
	
	public final void namespace(AST _t) throws RecognitionException {
		
		AST namespace_AST_in = (_t == ASTNULL) ? null : (AST)_t;
		AST p = null;
		AST uri = null;
		
		try {      // for error handling
			AST __t159 = _t;
			AST tmp79_AST_in = (AST)_t;
			match(_t,NAMESPACE);
			_t = _t.getFirstChild();
			p = (AST)_t;
			match(_t,PREFIX);
			_t = _t.getNextSibling();
			uri = (AST)_t;
			match(_t,NCName);
			_t = _t.getNextSibling();
			_t = __t159;
			_t = _t.getNextSibling();
			if ( inputState.guessing==0 ) {
				
						 NameManager.getInstance().addPrefix(p.getText(), uri.getText());
						
			}
		}
		catch (RecognitionException ex) {
			if (inputState.guessing==0) {
				reportError(ex);
				if (_t!=null) {_t = _t.getNextSibling();}
			} else {
			  throw ex;
			}
		}
		_retTree = _t;
	}
	
	public final WorldElement  formulaWithNs(AST _t) throws RecognitionException {
		WorldElement result = null;
		
		AST formulaWithNs_AST_in = (_t == ASTNULL) ? null : (AST)_t;
		
		try {      // for error handling
			{
			namespaceArea(_t);
			_t = _retTree;
			result=formula(_t);
			_t = _retTree;
			}
		}
		catch (RecognitionException ex) {
			if (inputState.guessing==0) {
				reportError(ex);
				if (_t!=null) {_t = _t.getNextSibling();}
			} else {
			  throw ex;
			}
		}
		_retTree = _t;
		return result;
	}
	
	public final WorldElement  modalFormula(AST _t) throws RecognitionException {
		WorldElement result = null;
		
		AST modalFormula_AST_in = (_t == ASTNULL) ? null : (AST)_t;
		WorldElement a; 
		String ag;
		
		try {      // for error handling
			if (_t==null) _t=ASTNULL;
			switch ( _t.getType()) {
			case BOX_BELIEF:
			{
				AST __t168 = _t;
				AST tmp80_AST_in = (AST)_t;
				match(_t,BOX_BELIEF);
				_t = _t.getFirstChild();
				ag=agent(_t);
				_t = _retTree;
				a=formula(_t);
				_t = _retTree;
				_t = __t168;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 ModalExpression mf = new ModalExpression(BeliefOperator.boxBelief(ag), a);
							 result = mf;
							
				}
				break;
			}
			case DIAMOND_BELIEF:
			{
				AST __t169 = _t;
				AST tmp81_AST_in = (AST)_t;
				match(_t,DIAMOND_BELIEF);
				_t = _t.getFirstChild();
				ag=agent(_t);
				_t = _retTree;
				a=formula(_t);
				_t = _retTree;
				_t = __t169;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 ModalExpression mf = new ModalExpression(BeliefOperator.diamondBelief(ag), a);
							 result = mf;
							
				}
				break;
			}
			default:
			{
				throw new NoViableAltException(_t);
			}
			}
		}
		catch (RecognitionException ex) {
			if (inputState.guessing==0) {
				reportError(ex);
				if (_t!=null) {_t = _t.getNextSibling();}
			} else {
			  throw ex;
			}
		}
		_retTree = _t;
		return result;
	}
	
	public final WorldElement  binaryBooleanFormula(AST _t) throws RecognitionException {
		WorldElement result = null;
		
		AST binaryBooleanFormula_AST_in = (_t == ASTNULL) ? null : (AST)_t;
		WorldElement a, b;
		
		try {      // for error handling
			if (_t==null) _t=ASTNULL;
			switch ( _t.getType()) {
			case COMMA:
			{
				AST __t171 = _t;
				AST tmp82_AST_in = (AST)_t;
				match(_t,COMMA);
				_t = _t.getFirstChild();
				a=formula(_t);
				_t = _retTree;
				b=formula(_t);
				_t = _retTree;
				_t = __t171;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 BinaryBooleanExpression bf = new BinaryBooleanExpression(BinaryBooleanExpression.Operator.OR, a, b);
							 result = bf;
							
				}
				break;
			}
			case AND:
			{
				AST __t172 = _t;
				AST tmp83_AST_in = (AST)_t;
				match(_t,AND);
				_t = _t.getFirstChild();
				a=formula(_t);
				_t = _retTree;
				b=formula(_t);
				_t = _retTree;
				_t = __t172;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 BinaryBooleanExpression bf = new BinaryBooleanExpression(BinaryBooleanExpression.Operator.AND, a, b);
							 ParserUtility.assignAndOperatorToBinarySubformulae(bf);
							 result = bf;
							
				}
				break;
			}
			case OR:
			{
				AST __t173 = _t;
				AST tmp84_AST_in = (AST)_t;
				match(_t,OR);
				_t = _t.getFirstChild();
				a=formula(_t);
				_t = _retTree;
				b=formula(_t);
				_t = _retTree;
				_t = __t173;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 BinaryBooleanExpression bf = new BinaryBooleanExpression(BinaryBooleanExpression.Operator.OR, a, b);
							 result = bf;
							
				}
				break;
			}
			default:
			{
				throw new NoViableAltException(_t);
			}
			}
		}
		catch (RecognitionException ex) {
			if (inputState.guessing==0) {
				reportError(ex);
				if (_t!=null) {_t = _t.getNextSibling();}
			} else {
			  throw ex;
			}
		}
		_retTree = _t;
		return result;
	}
	
	public final Formula  dlFormula(AST _t) throws RecognitionException {
		Formula f = null;
		
		AST dlFormula_AST_in = (_t == ASTNULL) ? null : (AST)_t;
		String t, u, conceptName; 
		Concept d, e;
		Role role1, role2;
		
		try {      // for error handling
			if (_t==null) _t=ASTNULL;
			switch ( _t.getType()) {
			case OBJECT_ROLE_ASSERTION:
			{
				AST __t175 = _t;
				AST tmp85_AST_in = (AST)_t;
				match(_t,OBJECT_ROLE_ASSERTION);
				_t = _t.getFirstChild();
				role1=role(_t);
				_t = _retTree;
				t=term(_t);
				_t = _retTree;
				u=term(_t);
				_t = _retTree;
				_t = __t175;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 ObjectRoleAssertion ra = new ObjectRoleAssertion(role1, t, u);
							 f = ra;
							
				}
				break;
			}
			case CONCEPT_ASSERTION:
			{
				AST __t176 = _t;
				AST tmp86_AST_in = (AST)_t;
				match(_t,CONCEPT_ASSERTION);
				_t = _t.getFirstChild();
				d=description(_t);
				_t = _retTree;
				t=uriReference(_t);
				_t = _retTree;
				_t = __t176;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 ConceptAssertion ca = new ConceptAssertion(d, t); 
							 f = ca;
							
				}
				break;
			}
			case EQUALS:
			{
				AST __t177 = _t;
				AST tmp87_AST_in = (AST)_t;
				match(_t,EQUALS);
				_t = _t.getFirstChild();
				d=description(_t);
				_t = _retTree;
				e=description(_t);
				_t = _retTree;
				_t = __t177;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 ConceptDefinition cd = new ConceptDefinition(ConceptDefinition.Type.NON_PRIMITIVE, d, e);
							 f = cd;
							
				}
				break;
			}
			case IMPLIES:
			{
				AST __t178 = _t;
				AST tmp88_AST_in = (AST)_t;
				match(_t,IMPLIES);
				_t = _t.getFirstChild();
				d=description(_t);
				_t = _retTree;
				e=description(_t);
				_t = _retTree;
				_t = __t178;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 ConceptDefinition cd = new ConceptDefinition(ConceptDefinition.Type.PRIMITIVE, d, e);
							 f = cd;
							
				}
				break;
			}
			case IMPLIES_ROLE:
			{
				AST __t179 = _t;
				AST tmp89_AST_in = (AST)_t;
				match(_t,IMPLIES_ROLE);
				_t = _t.getFirstChild();
				role1=role(_t);
				_t = _retTree;
				role2=role(_t);
				_t = _retTree;
				_t = __t179;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
					RoleInclusion ri = new RoleInclusion(role1, role2);
					f = ri;
					
				}
				break;
			}
			case TRANSITIVE:
			{
				AST __t180 = _t;
				AST tmp90_AST_in = (AST)_t;
				match(_t,TRANSITIVE);
				_t = _t.getFirstChild();
				role1=role(_t);
				_t = _retTree;
				_t = __t180;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
					RoleAssertion ra = new RoleAssertion(RoleAssertion.Type.TRANSITIVE, role1);
					f = ra;
					
				}
				break;
			}
			case DOUBLE_EQUAL:
			{
				AST __t181 = _t;
				AST tmp91_AST_in = (AST)_t;
				match(_t,DOUBLE_EQUAL);
				_t = _t.getFirstChild();
				t=uriReference(_t);
				_t = _retTree;
				u=uriReference(_t);
				_t = _retTree;
				_t = __t181;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
					SameIndividualAssertion sia = new SameIndividualAssertion(t, u);
					f = sia;
					
				}
				break;
			}
			default:
			{
				throw new NoViableAltException(_t);
			}
			}
		}
		catch (RecognitionException ex) {
			if (inputState.guessing==0) {
				reportError(ex);
				if (_t!=null) {_t = _t.getNextSibling();}
			} else {
			  throw ex;
			}
		}
		_retTree = _t;
		return f;
	}
	
	public final String  agent(AST _t) throws RecognitionException {
		String ag = null;
		
		AST agent_AST_in = (_t == ASTNULL) ? null : (AST)_t;
		AST agStr = null;
		AST str = null;
		
		try {      // for error handling
			if (_t==null) _t=ASTNULL;
			switch ( _t.getType()) {
			case VARIABLE:
			{
				agStr = (AST)_t;
				match(_t,VARIABLE);
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					ag = agStr.getText();
				}
				break;
			}
			case STRING_LITERAL:
			{
				str = (AST)_t;
				match(_t,STRING_LITERAL);
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					ag = str.getText();
				}
				break;
			}
			default:
			{
				throw new NoViableAltException(_t);
			}
			}
		}
		catch (RecognitionException ex) {
			if (inputState.guessing==0) {
				reportError(ex);
				if (_t!=null) {_t = _t.getNextSibling();}
			} else {
			  throw ex;
			}
		}
		_retTree = _t;
		return ag;
	}
	
	public final Role  role(AST _t) throws RecognitionException {
		Role role = null;
		
		AST role_AST_in = (_t == ASTNULL) ? null : (AST)_t;
		String roleName;
		
		try {      // for error handling
			if (_t==null) _t=ASTNULL;
			switch ( _t.getType()) {
			case DASH:
			{
				AST __t194 = _t;
				AST tmp92_AST_in = (AST)_t;
				match(_t,DASH);
				_t = _t.getFirstChild();
				roleName=uriReference(_t);
				_t = _retTree;
				_t = __t194;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 role = new Role(roleName, true);
							
				}
				break;
			}
			case NCName:
			case QNAME:
			{
				roleName=uriReference(_t);
				_t = _retTree;
				if ( inputState.guessing==0 ) {
					
							 role = new Role(roleName);
							
				}
				break;
			}
			default:
			{
				throw new NoViableAltException(_t);
			}
			}
		}
		catch (RecognitionException ex) {
			if (inputState.guessing==0) {
				reportError(ex);
				if (_t!=null) {_t = _t.getNextSibling();}
			} else {
			  throw ex;
			}
		}
		_retTree = _t;
		return role;
	}
	
	public final String  term(AST _t) throws RecognitionException {
		String term = null;
		
		AST term_AST_in = (_t == ASTNULL) ? null : (AST)_t;
		AST var = null;
		
		try {      // for error handling
			if (_t==null) _t=ASTNULL;
			switch ( _t.getType()) {
			case NCName:
			case QNAME:
			{
				term=uriReference(_t);
				_t = _retTree;
				break;
			}
			case VARIABLE:
			{
				var = (AST)_t;
				match(_t,VARIABLE);
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					term = var.getText();
				}
				break;
			}
			default:
			{
				throw new NoViableAltException(_t);
			}
			}
		}
		catch (RecognitionException ex) {
			if (inputState.guessing==0) {
				reportError(ex);
				if (_t!=null) {_t = _t.getNextSibling();}
			} else {
			  throw ex;
			}
		}
		_retTree = _t;
		return term;
	}
	
	public final Concept  description(AST _t) throws RecognitionException {
		Concept result = null;
		
		AST description_AST_in = (_t == ASTNULL) ? null : (AST)_t;
		Concept cd1, cd2;
		Role roleName;
		String conceptName, ag;
		int no;
		
		try {      // for error handling
			if (_t==null) _t=ASTNULL;
			switch ( _t.getType()) {
			case TILDE:
			{
				AST __t183 = _t;
				AST tmp93_AST_in = (AST)_t;
				match(_t,TILDE);
				_t = _t.getFirstChild();
				cd1=description(_t);
				_t = _retTree;
				_t = __t183;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 result = cd1.toggleNegated();
							
				}
				break;
			}
			case AMP:
			{
				AST __t184 = _t;
				AST tmp94_AST_in = (AST)_t;
				match(_t,AMP);
				_t = _t.getFirstChild();
				cd1=description(_t);
				_t = _retTree;
				cd2=description(_t);
				_t = _retTree;
				_t = __t184;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 BinaryConcept bd = new BinaryConcept(BinaryConcept.Constructor.INTERSECTION, cd1, cd2);
							 result = bd;
							
				}
				break;
			}
			case BAR:
			{
				AST __t185 = _t;
				AST tmp95_AST_in = (AST)_t;
				match(_t,BAR);
				_t = _t.getFirstChild();
				cd1=description(_t);
				_t = _retTree;
				cd2=description(_t);
				_t = _retTree;
				_t = __t185;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 BinaryConcept bd = new BinaryConcept(BinaryConcept.Constructor.UNION, cd1, cd2);
							 result = bd;
							
				}
				break;
			}
			case ALL:
			{
				AST __t186 = _t;
				AST tmp96_AST_in = (AST)_t;
				match(_t,ALL);
				_t = _t.getFirstChild();
				roleName=role(_t);
				_t = _retTree;
				cd1=description(_t);
				_t = _retTree;
				_t = __t186;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 RoleQuantification vr = new RoleQuantification(RoleQuantification.Constructor.ALL, roleName, cd1);
							 result = vr;
							
				}
				break;
			}
			case SOME:
			{
				AST __t187 = _t;
				AST tmp97_AST_in = (AST)_t;
				match(_t,SOME);
				_t = _t.getFirstChild();
				roleName=role(_t);
				_t = _retTree;
				cd1=description(_t);
				_t = _retTree;
				_t = __t187;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 RoleQuantification vr = new RoleQuantification(RoleQuantification.Constructor.SOME, roleName, cd1);
							 result = vr;
							
				}
				break;
			}
			case LESS_THAN_OR_EQ:
			{
				AST __t188 = _t;
				AST tmp98_AST_in = (AST)_t;
				match(_t,LESS_THAN_OR_EQ);
				_t = _t.getFirstChild();
				no=unsignedInt(_t);
				_t = _retTree;
				roleName=role(_t);
				_t = _retTree;
				cd1=description(_t);
				_t = _retTree;
				_t = __t188;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 QualifiedNoRestriction qr = new QualifiedNoRestriction(QualifiedNoRestriction.Constructor.AT_MOST, no, roleName, cd1);
							 result = qr;
							
				}
				break;
			}
			case GREATER_THAN_OR_EQ:
			{
				AST __t189 = _t;
				AST tmp99_AST_in = (AST)_t;
				match(_t,GREATER_THAN_OR_EQ);
				_t = _t.getFirstChild();
				no=unsignedInt(_t);
				_t = _retTree;
				roleName=role(_t);
				_t = _retTree;
				cd1=description(_t);
				_t = _retTree;
				_t = __t189;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 QualifiedNoRestriction qr = new QualifiedNoRestriction(QualifiedNoRestriction.Constructor.AT_LEAST, no, roleName, cd1);
							 result = qr;
							
				}
				break;
			}
			case LBRACE:
			{
				AST __t190 = _t;
				AST tmp100_AST_in = (AST)_t;
				match(_t,LBRACE);
				_t = _t.getFirstChild();
				conceptName=uriReference(_t);
				_t = _retTree;
				_t = __t190;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 Nominal nominal = new Nominal(conceptName);
							 result = nominal;
							
				}
				break;
			}
			case BOX_BELIEF:
			{
				AST __t191 = _t;
				AST tmp101_AST_in = (AST)_t;
				match(_t,BOX_BELIEF);
				_t = _t.getFirstChild();
				ag=agent(_t);
				_t = _retTree;
				cd1=description(_t);
				_t = _retTree;
				_t = __t191;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 result = new ModalConcept(BeliefOperator.boxBelief(ag), cd1);
							
				}
				break;
			}
			case DIAMOND_BELIEF:
			{
				AST __t192 = _t;
				AST tmp102_AST_in = (AST)_t;
				match(_t,DIAMOND_BELIEF);
				_t = _t.getFirstChild();
				ag=agent(_t);
				_t = _retTree;
				cd1=description(_t);
				_t = _retTree;
				_t = __t192;
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 result = new ModalConcept(BeliefOperator.diamondBelief(ag), cd1);
							
				}
				break;
			}
			case NCName:
			case QNAME:
			{
				conceptName=uriReference(_t);
				_t = _retTree;
				if ( inputState.guessing==0 ) {
					
							 ConceptName c = new ConceptName();
							 c.setName(conceptName);
							 result = c; 
							
				}
				break;
			}
			default:
			{
				throw new NoViableAltException(_t);
			}
			}
		}
		catch (RecognitionException ex) {
			if (inputState.guessing==0) {
				reportError(ex);
				if (_t!=null) {_t = _t.getNextSibling();}
			} else {
			  throw ex;
			}
		}
		_retTree = _t;
		return result;
	}
	
	public final String  uriReference(AST _t) throws RecognitionException {
		String absoluteUri = null;
		
		AST uriReference_AST_in = (_t == ASTNULL) ? null : (AST)_t;
		AST qname = null;
		AST uri = null;
		
		try {      // for error handling
			if (_t==null) _t=ASTNULL;
			switch ( _t.getType()) {
			case QNAME:
			{
				qname = (AST)_t;
				match(_t,QNAME);
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					
							 String qStr = qname.getText();
							 int colonIndex = qStr.indexOf(':');
							 String prefix = qStr.substring(0, colonIndex);
							 String label = qStr.substring(colonIndex + 1);
							 String namespace = NameManager.getInstance().getURI(prefix); // TODO: if null, throw exception
							 absoluteUri = namespace + label;
							
				}
				break;
			}
			case NCName:
			{
				uri = (AST)_t;
				match(_t,NCName);
				_t = _t.getNextSibling();
				if ( inputState.guessing==0 ) {
					absoluteUri = uri.getText();
				}
				break;
			}
			default:
			{
				throw new NoViableAltException(_t);
			}
			}
		}
		catch (RecognitionException ex) {
			if (inputState.guessing==0) {
				reportError(ex);
				if (_t!=null) {_t = _t.getNextSibling();}
			} else {
			  throw ex;
			}
		}
		_retTree = _t;
		return absoluteUri;
	}
	
	public final int  unsignedInt(AST _t) throws RecognitionException {
		int n = 0;
		
		AST unsignedInt_AST_in = (_t == ASTNULL) ? null : (AST)_t;
		AST theNo = null;
		
		try {      // for error handling
			theNo = (AST)_t;
			match(_t,UNSIGNED_INT);
			_t = _t.getNextSibling();
			if ( inputState.guessing==0 ) {
				n = Integer.parseInt(theNo.getText());
			}
		}
		catch (RecognitionException ex) {
			if (inputState.guessing==0) {
				reportError(ex);
				if (_t!=null) {_t = _t.getNextSibling();}
			} else {
			  throw ex;
			}
		}
		_retTree = _t;
		return n;
	}
	
	
	public static final String[] _tokenNames = {
		"<0>",
		"EOF",
		"<2>",
		"NULL_TREE_LOOKAHEAD",
		"SEMICOLON",
		"\"ns\"",
		"LPAREN",
		"PREFIX",
		"COLON",
		"NCName",
		"RPAREN",
		"BOX_BELIEF",
		"DIAMOND_BELIEF",
		"COMMA",
		"\"not\"",
		"IMPLIES_ROLE",
		"EQUALS",
		"IMPLIES",
		"\"transitive\"",
		"DOUBLE_EQUAL",
		"\"and\"",
		"\"or\"",
		"BAR",
		"AMP",
		"TILDE",
		"\"some\"",
		"\"all\"",
		"GREATER_THAN_OR_EQ",
		"LESS_THAN_OR_EQ",
		"LBRACE",
		"RBRACE",
		"DASH",
		"VARIABLE",
		"QNAME",
		"STRING_LITERAL",
		"UNSIGNED_INT",
		"WORLD",
		"CONCEPT_ASSERTION",
		"OBJECT_ROLE_ASSERTION",
		"CARET",
		"UNDERSCORE",
		"CHAR_ESC",
		"DIAMOND_OR_NCNAME",
		"PREFIX_LOCALNAME_OR_QNAME",
		"LOCAL_NAME",
		"NCBegin",
		"NCRest",
		"GREATER_THAN",
		"LESS_THAN",
		"HASH",
		"SLASH",
		"QUESTION",
		"LOWER_CASE_LETTER",
		"UPPER_CASE_LETTER",
		"LETTER",
		"DIGIT",
		"ALPHANUMERIC",
		"POINT",
		"LBRACKET",
		"RBRACKET",
		"WS"
	};
	
	private static final long[] mk_tokenSet_0() {
		long[] data = { 412321052672L, 0L};
		return data;
	}
	public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0());
	}
	
